﻿document.write("<script language=javascript src='DSWebsocketEngine.js'></script>");

function web_DSConnectionCheck()				{ConnectionTest();Invoke(arguments);}
function web_DSInitService()					{InitService("127.0.0.1:7999");}
function web_DSisConnectOn() 					{return ds_isConnectOn(); }
function web_Wait(timeout, cb) 					{Sleep(timeout, cb); }
function web_DSQuitSvc()                        {Invoke(arguments);}

/////////////////////////////////


function web_DSEnumPrinter()            		{Invoke(arguments);}
function web_DSOpenPrinter()   					{Invoke(arguments);}
function web_DSGetPrinterModel() 				{Invoke(arguments);}
function web_DSClosePrinter() 					{Invoke(arguments);}
function web_DSGetPrinterSN() 					{Invoke(arguments);}
function web_DSPrintTraceInfo() 				{Invoke(arguments);}
function web_DSDownloadFile()                   {Invoke(arguments);}
function web_DSPrintIssuePermit()               {Invoke(arguments);}
function web_DSZPLPrintText()                   {Invoke(arguments);}
function web_DSZPLPrintCode128()                {Invoke(arguments);}
function web_DSZPLSetFont()						{Invoke(arguments);}
function web_DSZPLBarCode128()                  {Invoke(arguments);}
function web_DSZPLPrintQrCode()                 {Invoke(arguments);}
function web_DSZPLPrintImage()					{Invoke(arguments);}
function web_DSZPLPrintLine()					{Invoke(arguments);}
function web_DSZPLSetPageLength()				{Invoke(arguments);}
function web_DSPrintQrCodeForLibrary()			{Invoke(arguments);}


function web_DAS_RFIDTag_Write_EPCID()			{Invoke(arguments);}
function web_DAS_RFIDTag_Write_EPCIDA()			{Invoke(arguments);}
function web_DAS_RFIDTag_Read_TIDEPCID()		{Invoke(arguments);}
function web_DSZPLPrintQrCodeExA()		    	{Invoke(arguments);}
function web_DSZPLPrintCode128A()			    {Invoke(arguments);}
function web_DSZPLPrintTextEx()		         	{Invoke(arguments);}
function web_DAS_RFIDTag_SetReadPower()		   	{Invoke(arguments);}
function web_DAS_RFIDTag_FetchReadPower()		{Invoke(arguments);}
function web_DAS_RFIDTag_SetWritePower()		{Invoke(arguments);}
function web_DAS_RFIDTag_FetchWritePower()		{Invoke(arguments);}
function web_DAS_RFID_TagForward()	        	{Invoke(arguments);}
function web_DAS_RFID_TagBackward()		        {Invoke(arguments);}
function web_DAS_RFID_Position_Adjustment()		{Invoke(arguments);}
function web_DAS_RFID_Automatic_Location()		{Invoke(arguments);}
function web_DSZPLRotation()		            {Invoke(arguments);}
function web_DSZPLSetCutter()	            	{Invoke(arguments);}
function web_DSGetMFG()	            	        {Invoke(arguments);}
///////////////////////////////
function web_DAS_RFIDTag_Read_EPCIDA()	        {Invoke(arguments);}
function web_DAS_RFIDTag_Read_TIDIDA()	        {Invoke(arguments);}
//////////////////////////////////////
function web_DSZPLPrintImageExA_SizeScalable()  {Invoke(arguments);}

function web_DSGetStarPrint()	                {Invoke(arguments);}
function web_DSGetReadEPC()	                    {Invoke(arguments);}


//////////////////////////////////////
function test_fun()                     		{Invoke("test_fun",1,2,3,[1,2],arguments[0]);} 


function DSInitService()
{
	web_DSInitService();
}

function DSLaunchApp()
{
	web_DSLaunchApp();
}

function web_DSLaunchApp()
{
	var a =document.createElement("a");
    //a.href="dsdraw:none";
	a.href="a1:none";
	//a.href="www.baidu.com";
	//a.display="none";
    document.body.appendChild(a);
    a.click();

    var c = arguments.length;
    if (c > 0) {
        if (typeof arguments[0] == "object") {
            var cb = arguments[0];
            Sleep(5000, cb);
        }
    }
}

function web_DSNewLaunchApp()
{
	var e = document.createElement("a");
	var reg = RegExp("^[A-Za-z0-9]+(://){1}$");
	if(arguments[0] && 
		typeof arguments[0] == "string" && reg.test(arguments[0]))
		e.href = arguments[0];
	else e.href = "DSWebPrtSvc://";//alert("error");
	e.innerHTML="";
	document.getElementsByTagName("body")[0].appendChild(e);
	
	
	var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串  
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器  
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
	var myHref;
	if(isIE || isIE11){
		//window.history.back(-1);
		myHref = window.location.href;
		
	} 
	e.click();
	if(isIE || isIE11){
		//window.history.back(-1);
		var textHref = window.location.href;
		if(myHref != window.location.href)
		window.history.back(-1);
	} 
	
	document.getElementsByTagName("body")[0].removeChild(e);
}

function web_DSPrtEngineStartup1()
{
	DSInitService();
    web_Wait(1000, function (res) {
        if (!res) {
            alert("服务未启动，请启动服务；");
            DSLaunchApp();
            web_Wait(15000, function (res) {
                if (!res)
                    output("启动服务失败");
                else
                    output("启动服务成功");
            });
        }
        else
            output("启动服务成功");
    });
}

function web_DSPrtEngineStartup(callBackFun,ifOpen)
{
	if("function" != typeof arguments[0])return;
	DSInitService();
	
    web_Wait(1000, function (res) {
        if (!res) {
            callBackFun(-1);
            if(true == ifOpen)web_DSNewLaunchApp("DSWebPrtSvc://");
            web_Wait(15000,callBackFun);
        }
        else
            callBackFun(true);
    });
}
